package com.seekprice.core;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Test {

	private static final String BUY360_URL="http://search.360buy.com/Search?keyword=";
	
	private static final String KEY="G470";
	
	public static void main(String[] args) throws Exception {
		Document doc = Jsoup.connect(BUY360_URL+KEY)
				  .userAgent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")
				  .timeout(3000)
				  .post();
		Elements resultList= doc.select("#plist");
        Elements productList = resultList.select("li");

        System.out.println("查询关键字为...........:G470");
        for(int i=0;i<productList.size();i++){
            Element product = productList.get(i);
            String title=product.getElementsByClass("p-name").first().getElementsByTag("a").first().text();
            if (title.contains(KEY)==false){
            	continue;
            }
            String url=product.getElementsByClass("p-name").first().getElementsByTag("a").first().attr("href");
            String img=product.getElementsByClass("p-img").first().select("img").first().attr("src");
            String price=product.getElementsByClass("p-price").first().getElementsByTag("del").first().text();
            String evaluateUrl=product.getElementsByClass("extra").first().getElementsByTag("a").first().attr("href");
            String evaluateQuantity=product.getElementsByClass("extra").first().getElementsByTag("a").first().text();
            System.out.println("title:"+title);
            System.out.println("url:"+url);
            System.out.println("img:"+img);
            System.out.println("price:"+price);
            System.out.println("evaluateUrl:"+evaluateUrl);
            System.out.println("evaluateQuantity:"+evaluateQuantity);
        }
	}
}
